package com.itheima.service.pmsService.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.pms.PmsSkuStock;
import com.itheima.mapper.pmsMapper.PmsSkuStockMapper;
import com.itheima.service.pmsService.PmsSkuStockService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsSkuStockServiceImpl implements PmsSkuStockService {
    @Autowired
    PmsSkuStockMapper pmsSkuStockMapper;

    @Override
    public void add(PmsSkuStock pmsSkuStock) {
        pmsSkuStockMapper.insert(pmsSkuStock);
    }

    @Override
    public List<PmsSkuStock> getInfoByBrandId(Long id) {
        LambdaQueryWrapper<PmsSkuStock> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsSkuStock::getProductId, id);

        return pmsSkuStockMapper.selectList(lqw);
    }

    @Override
    public void update(PmsSkuStock pmsSkuStock) {
        pmsSkuStockMapper.updateById(pmsSkuStock);
    }

    @Override
    public void updateByIdList(Integer pid, PmsSkuStock[] pmsSkuStock) {

        for (PmsSkuStock skuStock : pmsSkuStock) {
            skuStock.setProductId(pid.longValue());
            pmsSkuStockMapper.updateById(skuStock);
        }
    }

    @Override
    public List<PmsSkuStock> selectByIdSku(Integer pid, String skuCode) {

        LambdaQueryWrapper<PmsSkuStock> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsSkuStock::getProductId,pid);
        lqw.like(StrUtil.isNotEmpty(skuCode),PmsSkuStock::getSkuCode,skuCode);

        List<PmsSkuStock> pmsSkuStockList = pmsSkuStockMapper.selectList(lqw);
        return pmsSkuStockList;
    }
}
